package cj.web.uc.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.paoding.rose.web.annotation.Path;
import net.paoding.rose.web.annotation.rest.Post;
import net.sf.json.JSONObject;

import org.springframework.beans.factory.annotation.Autowired;

import cj.web.constants.PayStatusEnum;
import cj.web.uc.service.MemberService;
import cj.web.uc.service.VideoUcService;
import cj.web.yc.utils.Constants;
import cj.web.yc.utils.ReturnUUID;

/**
 * 充值
 * @author Administrator
 *
 */
@Path("videoOrder")
public class VideoOrderController extends BaseController {

	@Autowired
	private MemberService memberService;
	@Autowired
	private VideoUcService videoUcService;
	
	/**
	 * 创建订单
	 * @param price
	 * @param payWay
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@Post("createOrder")
	public synchronized String createOrder(String price,int payWay,
			HttpServletRequest request,HttpServletResponse response) throws Exception{
		JSONObject jo = new JSONObject();
		jo.put("returnFlag", Constants.returnObj.returnFlag_true);
		
		try {
			String memberId = getCookieValueByName(request, "memberId");
			String phone = getCookieValueByName(request, "phone");
			
			String orderNo = ReturnUUID.getOrderNo("YC");
			int status = PayStatusEnum.WFK.getValue();
			
			int orderId = videoUcService.createOrder(0, orderNo, Integer.parseInt(memberId), price, status, phone, phone);
			jo.put("orderId", orderId);
			jo.put("price", price);
		} catch (Exception e) {
			// TODO: handle exception
			jo.put("returnFlag", Constants.returnObj.returnFlag_flase);
		}
		
		return "@" + jo.toString();
	}
}